<?php

namespace app\controller\bossManager;

use app\validate\PageValidate;
use app\validate\OssProductValidate;
use app\service\OssProductService;

class OssProductController extends WebBossController{
    public function initValidate(){        
        $this->validate = new OssProductValidate();
    }

    public function list_action(){  
        $input = $this->check();        
        $page = $this->check('pageInfo',null,(new PageValidate()));        
        $data = OssProductService::getListInfo($input,$page);
        $total = OssProductService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

    public function set_action(){  
        $input = $this->check();
        $res = OssProductService::edit($input); 
        return self::ok($res);
    }

 
    public function del_action(){ 
        $input = $this->check();
        $res = OssProductService::delById($input['id']); 
        return self::ok($res);
    }

    public function simple_all_action(){ 
        $data = OssProductService::getNativeAll([],['id','sku','name']);
        return self::ok($data); 
    }



    /**
     * 商品分配
     */
    public function assign_action(){
        $input = $this->check();
        $openAppId = $input['open_app_id'];
        $products = $input['products'];
        foreach($products as $product){
            $this->check('assign_item',$product);
        }
        $data = OssProductService::assign($openAppId,$products);
        return self::ok($data);
    }

    /**
     * 已分配信息
     */
    public function assign_info_action(){
        $input = $this->check('del');
        $data = OssProductService::getAssignedInfo($input['id']);
        return self::ok($data);
    }
}